import { http } from './request';

// 地区相关API
export const areaApi = {
  // 获取省市区列表
  getAreaList: () => {
    return http.post('/api/area/list')
  },
  // 获取国家列表
  getCountries: () => {
    return http.post('/api/area/countries')
  },
  // 获取货币符号
  getCurrencySymbol: () => {
    return http.post('/api/area/currencySymbol')
  }
}

// 用户相关API
export const userApi = {
  // 登录
  login: (data: { userName: string; password: string }) => {
    return http.post('/api/member/login', data)
  },

  // Google登录
  googleLogin: (data: { idToken: string }) => {
    return http.post('/api/auth/google', data)
  },

  // 注册
  register: (data: { userName: string; password: string; email: string }) => {
    return http.post('/api/member/register', data)
  },

  // 获取用户信息
  getUserInfo: () => {
    return http.post('/api/member/get')
  },

  // 更新用户信息
  updateUserInfo: (data: any) => {
    return http.post('/api/member/update', data)
  },

  // 退出登录
  logout: () => {
    return http.post('/api/auth/logout')
  },

  getRecordsList: (params: { pageSize: number; pageNum: number }) => {
    return http.post('/api/records/list', params)
  },

  // 获取记录详情
  getRecordDetail: (recordId: string) => {
    return http.post(`/api/records/detail/${recordId}`)
  }
}

// 文件相关API
export const fileApi = {
  // 上传文件
  upload: (file: File) => {
    return http.upload('/api/file/upload', file)
  },

  // 下载文件
  download: (fileId: string, filename?: string) => {
    return http.download(`/api/file/download/${fileId}`, filename)
  }
}

// 数据相关API
export const dataApi = {
  // 获取列表数据
  getList: (params: any) => {
    return http.get('/api/data/list', { params })
  },

  // 获取详情
  getDetail: (id: string) => {
    return http.get(`/api/data/detail/${id}`)
  },

  // 创建数据
  create: (data: any) => {
    return http.post('/api/data/create', data)
  },

  // 更新数据
  update: (id: string, data: any) => {
    return http.put(`/api/data/update/${id}`, data)
  },

  // 删除数据
  delete: (id: string) => {
    return http.delete(`/api/data/delete/${id}`)
  }
}

// Banner相关API
export const bannerApi = {
  // 获取banner列表
  getList: () => {
    return http.post('/api/banner/list')
  }
}

// 联系我们相关API
export const contactApi = {
  // 获取联系信息
  getContactInfo: () => {
    return http.post('/api/contact/us')
  }
}

// 专家相关API
export const expertApi = {
  // 获取专家列表
  getList: (params: { pageSize: number; pageNum: number }) => {
    return http.post('/api/expert/list', params)
  },

  // 获取专家详情
  getDetail: (id: number) => {
    return http.post(`/api/expert/get/${id}`)
  }
}

// 新闻相关API
export const newsApi = {
  // 获取新闻列表
  getList: (params: { pageSize: number; pageNum: number }) => {
    return http.post('/api/information/list', params)
  },

  // 获取新闻详情
  getDetail: (id: number) => {
    return http.post(`/api/news/get/${id}`)
  }
}

// 文章相关API
export const articleApi = {
  // 获取文章列表（分页 + 分类）
  getList: (params: { pageSize: number; pageNum: number; categoryId: number }) => {
    return http.post('/api/article/list', params)
  },
  // 获取文章详情
  getDetail: (id: number) => {
    return http.post(`/api/article/get/${id}`)
  }
}

// 快速链接相关API
export const linksApi = {
  // 获取快速链接列表
  getList: () => {
    return http.post('/api/links/list')
  }
}

// 申报/统计相关API
export const countApi = {
  // 行业列表
  listIndustry: (data?: any) => {
    return http.post('/api/count/listIndustry', data || {})
  },
  getFormParams: (industryId: number) => {
    return http.post(`/api/count/formParams/${industryId}`)
  },
  saveRecord: (data: any) => {
    return http.post('/api/records/save', data)
  }
}

// 设置默认配置
export const setupApi = () => {
  // 设置baseURL
  http.setBaseURL('https://cbam.hongyuan3e.com/prod-api')
  
  // 设置默认请求头
  http.setDefaultHeaders({
    'X-Client-Version': '1.0.0',
    'X-Platform': 'web'
  })
}

// 导出所有API
export default {
  area: areaApi,
  user: userApi,
  file: fileApi,
  data: dataApi,
  banner: bannerApi,
  contact: contactApi,
  expert: expertApi,
  news: newsApi,
  article: articleApi,
  count: countApi,
  links: linksApi,
  setup: setupApi
} 